#include <iostream>
using namespace std;
int dp[1001][1001];
int main() {
    int n;
    cin >> n;
    int tmp;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            cin>>tmp;
            dp[i][j] = max(dp[i-1][j-1], dp[i-1][j])+tmp;
        }
    }
    int res=0;
    for(int j=1;j<=n;j++){
        res = max(res, dp[n][j]);
    }
    cout<<res<<endl;
    return 0;
}